package org.example.task.controller;


import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.example.task.model.dto.taskcomment.CreateTaskComment;
import org.example.task.model.po.TaskComment;
import org.example.task.model.vo.R;
import org.example.task.service.ITaskCommentService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 评论模块
 *
 * @module 评论模块
 */
@RestController
@RequestMapping("/task-comment")
@RequiredArgsConstructor
public class TaskCommentController {
    private final ITaskCommentService taskCommentService;

    /**
     * 任务评论
     *
     * @param comment 评论
     * @return 结果
     */
    @PreAuthorize("hasAuthority('task_comment')")
    @PostMapping()
    public R comment(@Valid @RequestBody CreateTaskComment comment) {
        boolean flag = taskCommentService.createComment(comment);
        if (flag) {
            return R.success();
        }
        return R.error("评论失败");
    }
}
